<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>预警提示</title>
<style>
.content_table {
	border: 1px solid #8DB2E3
}

.content_table td {
	height: 24px;
	padding: 5px
}

.content_table {
	width: 100%;
	border-collapse: collapse
}

.grid th {
	background: #E7F3FE;
	height: 27px;
	line-height: 27px;
	border: 1px solid #8DB2E3;
	padding-left: 5px
}

.content_table td {
	border: 1px solid #8DB2E3;
	padding-left: 5px
}
</style>
</head>

<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">设备维保预警详情</div>
		</div>
	</div>
	<div class="new-form">
		<div>
			<form id="ff" method="post">
				<table cellpadding="5" style="margin: auto;">
					<tr>
						<td style="width: 100px;">设备维保记录:</td>
						<td>
							<input style="width: 100%;" id="equipment" name="equipment" class="easyui-combobox" editable="false"
								readonly="true" data-options="valueField:'id',textField:'name',panelHeight: 'auto'">
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">是否开机：</td>
						<td>
							<input class="easyui-checkbox" name="isopen" id="isopen" readonly="true">
						</td>
					</tr>
					<tr id="tr1" style="display: none;">
						<td style="width: 100px;">开机时间：</td>
						<td>
							<input class="easyui-datetimebox" id="starttime" name="starttime" style="width: 100%;" editable="false"
								readonly="true" />
						</td>
					</tr>
					<tr id="tr2" style="display: none;">
						<td style="width: 100px;">开机时长（小时）：</td>
						<td>
							<input class="easyui-textbox" id="intervaltime" name="intervaltime" style="width: 100%;"
								data-options="validType:'number'" readonly="true" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">是否维保：</td>
						<td>
							<input class="easyui-checkbox" name="isdaily" id="isdaily" readonly="true">
						</td>
					</tr>
					<tr id="tr3" style="display: none;">
						<td style="width: 100px;">维保时间：</td>
						<td>
							<input class="easyui-datetimebox" id="createtime" name="createtime" style="width: 100%;"
								editable="false" readonly="true" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">备注：</td>
						<td>
							<input class="easyui-textbox" id="remark" name="remark" style="width: 100%;" readonly="true" />
						</td>
					</tr>
				</table>
			</form>
			<div style="text-align: right;" class="search-input" id="div2">
				<a href="#" class="d-btn btn-green" onclick="displayAtt()">查看附件</a>
			</div>
			<div style="text-align: center;" id="div1">
				<a href="#" class="d-btn btn-blue" onclick="savePro()">已处理</a>
			</div>
		</div>
	</div>
	<div style="display: none">
		<div id="displayAtt" class="datagrid-toolbar"
			style="width: 98%; max-height: 80%; padding: 5px; text-align: center;"></div>
	</div>
</body>
<script th:inline="javascript">
	var currentPro = [[${equipmentMark}]];
	
	$(document).ready(function() {
		$("#equipment").combobox("setValue", currentPro.equipment.name);
		$("#remark").textbox("setValue", currentPro.remark);
		if (currentPro.starttime != null){
			$("#isopen").checkbox('check');
			$("#starttime").datetimebox("setValue", parsedate(currentPro.starttime));
			$("#starttime").datetimebox("width", $("equipment").width());
			$("#intervaltime").textbox("setValue", currentPro.intervaltime);
			$("#intervaltime").datetimebox("width", $("equipment").width());
		}
		if (currentPro.isdaily == 1){
			$("#isdaily").checkbox('check');
			$("#createtime").datetimebox("setValue", parsedate(currentPro.createtime));
			$("#createtime").datetimebox("width", $("equipment").width());
		}
	});
	
	function savePro() {
		currentPro.status = 2;
		$.ajax({
			type : 'POST',
			url : "../equipmentMarkUpdate.do",
			data : JSON.stringify(currentPro),
			contentType : "application/json",
			success : function(data) {
				if (data.success){
					$.messager.alert('保存', '保存成功', 'success');
				}else{
					$.messager.alert('保存', '保存失败', 'error');
				}
				window.setInterval("window.location.href=document.referrer", 2000);
			},
			dataType : "json"
		});
	}
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(),month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(),hour = date.getHours(),min = date.getMinutes(),sec = date.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
	function parsedate(value) {
		var date = new Date(value);
		var year = date.getFullYear();
		var month = date.getMonth() + 1; //月份+1   
		var day = date.getDate();
		var hour = date.getHours();
		var minutes = date.getMinutes();
		var second = date.getSeconds();
		return day + "/" + month + "/" + year + " " + hour + ":" + minutes + ":" + second;
	}
	function displayAtt() {
		var row = currentPro;
		var tb = "";
		$.each(row.attachments,function(i,val) {
			if(isImage(val.url)){
				tb+= '<img onclick="window.open(\'../'+val.url+ 
				'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" '+
				'src="../'+val.url+'" style="width:100px;"><br><span>'+val.name+'</span><br>';
			}else{
				tb+= '<a href="javascript:void(0)" onclick="attachmentFile('+val.id+',\''+val.name+
				'\')"><span>'+val.name+'</span></a><br>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
			title : '附件',
			resizable : true,
			closed : false,
			cache : false,
			modal : true
		});
	}
	function attachmentFile(id,name) {
		$.get('../attachmentFile.do?id=' + id, function(data) {
			blob = new Blob([ data ])
			var a = document.createElement('a');
			a.download = name;
			a.href = window.URL.createObjectURL(blob)
			a.click()
		})
	}
	function isImage(url) {
		var index= url.lastIndexOf(".");
		var ext = url.substr(index+1);
		return [ 'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff' ,'ico'].
				indexOf(ext.toLowerCase()) !== -1;
	}
</script>

</html>